<#include "/includes/vars.inc"> 
<#assign packageDir = project.@rootPackage?replace(".","/")>
<@pp.dropOutputFile />
<@pp.changeOutputFile name="${javaDir}${packageDir}/web/support/LocaleController.java" />

package ${project.@rootPackage}.web.support;

import ${project.@rootPackage}.web.util.JsfUtil;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


/**
 * LocaleController class
 * <#if project.@author[0]??>@author ${project.@author}</#if>
 */
@Controller(value="localeController")
@Scope("session")
public class LocaleController {

	protected static final Logger logger = Logger.getLogger("LocaleController");
    private Locale locale;

    @PostConstruct
    public void init() {
        locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
        locale = new Locale("es","Es");
        logger.log(Level.INFO,"Init locale to {0}",locale);
    }

    public Locale getLocale() {
        return locale;
    }

    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    public void changeLocale() {
        String language = JsfUtil.getParameter("language");
        String country = JsfUtil.getParameter("country");
        this.setLocale(new Locale (language,country));
        logger.log(Level.INFO,"Change locale to {0}",locale);
    }
    
   
}